/*

  The contents of this file are subject to the Mozilla Public License Version
  1.1 (the "License"); you may not use this file except in compliance with
  the License. You may obtain a copy of the License at 
  
           http://www.mozilla.org/MPL/ 
  
  Software distributed under the License is distributed on an "AS IS" basis,
  WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  for the specific language governing rights and limitations under the License. 
  
  The Original Code is Tamina Framework.
  
  The Initial Developer of the Original Code is
  MOUTON David (aka damo)  <damo@tamina-online.com>.
  Portions created by the Initial Developer are Copyright (C) 2004-2007
  the Initial Developer. All Rights Reserved.
  
  Contributor(s) :
  
*/
package org.tamina.core.lang
{
	public const LangManager:_LangManager = new _LangManager();
	
}
import org.tamina.core.init.IInitializable;
import flash.events.EventDispatcher;
import flash.events.Event;
import org.tamina.utils.RessourceBundle;
import org.tamina.utils.PropertiesBundle;
import org.tamina.core.init.InitEvent;
internal class _LangManager extends EventDispatcher implements IInitializable
{
	//Props
	private const CLASS_NAME:String="LangInitializer";
	private var __urlProperties:String="./langueData.properties";
	private var __langueBundle:RessourceBundle;
	private var __isInitialized:Boolean=false;
	
	
	//Constructeur
	function _LangManager(){
		
	}
	
	//Methodes publiques
	
	/**
	 * Debute l'initialisation
	 * 
	 */	
	public function init():void{
		__langueBundle = new PropertiesBundle("mainLanguage");
		__langueBundle.addEventListener(Event.COMPLETE,endInit);
		__langueBundle.loadRessource(__urlProperties);

	}
	
	/**
	 * Retourne le nom de la classe
	 * @return 
	 * 
	 */	
	public function getName():String{
		return CLASS_NAME;
	}
	
	/**
	 * Declare le chemin vers le fichier de ressource contenant les info de langue
	 * @param path
	 * 
	 */	
	public function set urlProperties(path:String):void{
		__urlProperties = path;
	}
	
	public function getLangBundle():RessourceBundle{
		if(__isInitialized){
			return __langueBundle;
		} else {
			return null;
		}
	}
	
	//Methodes privées
	private function endInit(e:Event):void{
		
		__isInitialized = true;
		__langueBundle.removeEventListener(Event.COMPLETE,endInit);
		dispatchEvent(new InitEvent(InitEvent.INITIALIZED));
	}

}